import java.util.Scanner;

import static java.lang.Math.max;

public class test2 {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] nums = new int[n];

        for(int i=0;i<n;i++) nums[i]=sc.nextInt();

        int maxSum=nums[0],now=0;

        for(int i=0;i<n;i++){
            now=max(now+nums[i],nums[i]);
            maxSum=max(maxSum,now);
        }
        System.out.println(maxSum);
    }
}